package com.demo6.controller;

import com.demo6.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

//@Controller
//@RestController=@Controller+@ResponseBody
@RestController
@RequestMapping("/tt")
public class hellocontroller {
    //@Autowired
    //private Environment env;
    //通过@Value注解的形式读取
    @Value("${student.sno}")
    private String sno;
    @Value("${student.sname}")
    private String sname;
    @Value("${student.sage}")
    private Integer sage;
    @Value("${student.sgender}")
    private String sgender;
    //获取application.properties中的内容
    @RequestMapping("/readinfo")
    public Student readinfo(){
        //读取配置文件的值
//        String sno=env.getProperty("student.sno");
//        String sname=env.getProperty("student.sname");
//        Integer sage=Integer.parseInt(env.getProperty("student.sage"));
//        String sgender=env.getProperty("student.sgender");
        //创建学生对象
        Student stu=new Student();
        stu.setSno(sno);
        stu.setSname(sname);
        stu.setSage(sage);
        stu.setSgender(sgender);
        return stu;
    }
    @RequestMapping("/hello")
    //@ResponseBody
    public String hello() {
        return "hello springboot-2";
    }
}
